<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="https://unpkg.com/axios/dist/axios.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
</head>

<body>
    <div id="app">
        <input type="text" @keyup.enter="get" v-model="city"><button @click="get">搜索</button>
        <div>
            <a href="#" @click="change('长沙')">长沙</a>
            <a href="#" @click="change('武汉')">武汉</a>
            <a href="#" @click="change('西安')">西安</a>
        </div>
        <ul>
            <li v-for="item in weather">
                <span>{{  item.type  }}</span>
                <span>{{  item.low  }}</span>
                <span>{{  item.high  }}</span>
                <span>{{  item.date  }}</span>
            </li>
        </ul>
    </div>
    <script>
        var app = new Vue({
            el: "#app",
            data: {
                city: "",
                weather: []
            },
            methods: {
                get: function () {
                    var that = this;
                    axios.get("http://wthrcdn.etouch.cn/weather_mini?city=" + this.city)
                        .then(function (response) {
                            that.weather = response.data.data.forecast;
                        }).catch(function (err) {

                        })
                },
                change: function (city) {
                    this.city = city;
                    this.get();
                }
            }
        })
    </script>
</body>

</html>